package com.pkuse.bjousystem.utils;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;

import java.util.Map;

public class PageUtils {

    /**
     * Layui通过reqeust body传递page信息，而且当前页从1开始，spring从0开始，所以递减一层
     */
    public static Pageable fromRequest(Map<String, String> requestBody) {
       return PageRequest
               .of(Integer.valueOf(requestBody.get("page")), Integer.valueOf(requestBody.get("size")))
               .previousOrFirst();
    }
}
